#include "logging.h"


#include <iostream>

int LoggingService::s_output_level = 2;

std::string LoggingService::s_levels[7] = {
    "",
    " VERBOSE ",
    " DEBUG   ", 
    " INFO    ", 
    " WARNING ", 
    " ERROR   ", 
    " FATAL   "
  };


LoggingService::LoggingService(const std::string& n)
{
  m_log_prefix = n; 
  for (unsigned int i = 0 ; i < 15 - n.size(); i++)
  {
    m_log_prefix = m_log_prefix + " ";
  }
  endl = "\r\n";
}

std::ostream& LoggingService::output(int l, const std::string& prefix)
{
  if (l < 1 || l > 6) return std::clog;

  std::clog << s_levels[l];
  std::clog << prefix;

  std::clog.clear(
      (LoggingService::outputLevel() <= l)?
      std::ios_base::goodbit 
      : std::ios_base::badbit
      );
  return std::clog;
}

std::ostream& LoggingService::verbose()
{
  return LoggingService::output(1, m_log_prefix);
}

std::ostream& LoggingService::debug()
{
  return LoggingService::output(2, m_log_prefix);
}

std::ostream& LoggingService::info()
{
  return LoggingService::output(3, m_log_prefix);
}

std::ostream& LoggingService::warning()
{
  return LoggingService::output(4, m_log_prefix);
}

std::ostream& LoggingService::error()
{
  return LoggingService::output(5, m_log_prefix);
}

std::ostream& LoggingService::fatal()
{
  return LoggingService::output(6, m_log_prefix);
}




int LoggingService::outputLevel()
{
  return s_output_level;
}

void LoggingService::setOutputLevel(int l)
{
  s_output_level = l;
}
